<template>
	<view>
		<view class="gui-margin-top" style="margin-left: 20rpx;">
			<text class="gui-h6 gui-color-green gui-bold">可提现金额：￥{{tixian_money}}</text>
		</view>
		<view class="gui-margin-top" style="margin-left: 20rpx;">
			<text class="gui-h6 gui-color-black gui-bold">手续费：{{teacher_shouxu}}%</text>
		</view>

		<view class="gui-form-item gui-border-b" style="margin-left: 20rpx;width: 90%;">
			<text class="gui-form-label">提现金额</text>
			<view class="gui-form-body">
				<input type="number" class="gui-form-input" v-model="money" name="money" @input="inputting"
					placeholder="请输入提现金额" />
			</view>
			<text class="gui-form-icon gui-icons gui-text-center gui-color-gray" v-if="money.length >= 1"
				@click="clearName2">&#xe78a;</text>
		</view>

		<view class="gui-margin-top" style="margin-left: 20rpx;">
			<text class="gui-h6 gui-color-red">注意：</text>
		</view>

		<view class="gui-margin-top" style="margin-left: 20rpx;">
			<text class="gui-h6 gui-color-red">1. 提现金额不能大于可提现金额，必须输入整数</text>
		</view>

		<view class="gui-margin-top" style="margin-left: 20rpx;">
			<text class="gui-h6 gui-color-red">2. 单次提现金额不能小于{{low_tixian_money}}元</text>
		</view>

		<view class="gui-margin-top" style="margin-left: 20rpx;">
			<text class="gui-h6 gui-color-red">3. 一个月只能申请{{tixian_num}}次</text>
		</view>

		<view class="gui-margin-top-large gui-flex gui-rows gui-nowrap gui-justify-content-end"
			style="margin-right: 20rpx;">
			<button type="default" class="gui-button gui-bg-blue" style="width:200rpx;" @tap="add_tixian()">
				<text class="gui-icons gui-color-white gui-button-text">提交</text>
			</button>
		</view>

		<gui-modal ref="guimodal1" title="提示">
			<view slot="content" class="gui-padding gui-bg-gray">
				<text class="gui-block-text gui-text-center gui-text gui-color-red"
					style="line-height:100rpx; padding:10rpx;">当前提现需扣除手续费{{shouxu_money}}元，是否提交？</text>
			</view>
			<!-- 利用 flex 布局 可以放置多个自定义按钮哦  -->
			<view slot="btns" class="gui-flex gui-rows gui-space-between">
				<view class="modal-btns gui-flex1" style="margin-right:80rpx;">
					<text class="modal-btns gui-color-gray" @tap="close1">取消</text>
				</view>
				<view class="modal-btns gui-flex1" style="margin-left:80rpx;">
					<text class="modal-btns gui-color-blue" @tap="confirm1">确认</text>
				</view>
			</view>
		</gui-modal>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				tixian_money: 0,
				money: '',
				teacher_shouxu: 0,
				low_tixian_money: 0,
				tixian_num: 0,
				shouxu_money: 0
			}
		},
		onLoad: function(query) {
			this.$globalMethod();
			this.tixian_details();
		},
		methods: {
			taped: function(idx) {
				console.log(idx);
			},
			inputting() {

			},
			clearName2() {
				this.money = '';
			},
			confirm1() {
				let _this = this;
				_this.graceJS.post(_this.serverUrl + '/api.shop/add_tixian', {
					money: _this.money
				}, 'json', {
					token: _this.token
				}, (res) => {
					
					_this.close1();
					
					if (res.code == 0) {
						uni.navigateTo({
							url: '/pages/shop/shouru',
							success: function() {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}, (e) => {
					_this.close1();
					uni.showToast({
						title: '网络请求失败，请稍后再试',
						icon: 'none'
					})
				})
			},
			close1() {
				this.$refs.guimodal1.close();
			},
			tixian_details() {
				let _this = this;
				_this.graceJS.get(_this.serverUrl + '/api.shop/tixian_details', {}, {
					token: _this.token
				}, (res) => {
					if (res.code == 0) {
						_this.tixian_money = res.data.tixian_money;
						_this.teacher_shouxu = res.data.teacher_shouxu;
						_this.low_tixian_money = res.data.min_tixian_money;
						_this.tixian_num = res.data.tixian_num;
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}, (e) => {
					uni.showToast({
						title: '网络请求失败，请稍后再试',
						icon: 'none'
					})
				})
			},
			add_tixian() {
				let _this = this;


				if (_this.money == '') {
					uni.showToast({
						title: '提现的金额不能为空',
						icon: 'none'
					});

					return;
				}

				if (_this.money <= 0) {
					uni.showToast({
						title: '提现的金额必须大于0元',
						icon: 'none'
					});

					return;
				}

				if (_this.money > _this.tixian_money) {
					uni.showToast({
						title: '提现的金额不能超过可提现金额',
						icon: 'none'
					});

					return;
				}
				
				if(_this.money < _this.low_tixian_money){
					uni.showToast({
						title: '提现金额不能少于'+_this.low_tixian_money+'元',
						icon: 'none'
					});
					
					return;
				}
				


				_this.shouxu_money = _this.money * (_this.teacher_shouxu / 100);

				this.$refs.guimodal1.open();


			}
		}
	}
</script>

<style>
	.gui-text-small {
		line-height: 50rpx;
	}

	.modal-btns {
		line-height: 88rpx;
		font-size: 26rpx;
		text-align: center;
		width: 200rpx;
	}
</style>